﻿using BanquetPortion.Database;
using BanquetPortion.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BanquetPortion.Services
{
    public class BanquetGiftPeopleRepostory : IBanquetGiftPeopleRepostory
    {
        private readonly AppDbContext _context;
        public BanquetGiftPeopleRepostory(AppDbContext context)
        {
            _context = context;
        }
        public async Task<IEnumerable<BanquetGiftPeople>> GetBanquetGiftPeopleAsync()
        {
            return await _context.BanquetGiftPeoples.ToArrayAsync();
        }
        public async Task<BanquetGiftPeople> GetBanquetGiftPeopleByIdAsync(int banquetGiftPeopleId)
        {
            return await _context.BanquetGiftPeoples.FirstOrDefaultAsync(d => d.Id == banquetGiftPeopleId);
        }
        public void CreateBanquetGiftPeople(BanquetGiftPeople BanquetGiftPeople)
        {
            _context.BanquetGiftPeoples.Add(BanquetGiftPeople);
        }
        public void DeleteBanquetGiftPeople(BanquetGiftPeople banquetGiftPeople)
        {
            _context.BanquetGiftPeoples.Remove(banquetGiftPeople);
        }
        public async Task<bool> BanquetGiftPeopleExistsAsync(int banquetGiftPeopleId)
        {
            return await _context.BanquetGiftPeoples.AnyAsync(d => d.Id == banquetGiftPeopleId);
        }
        public async Task<bool> SaveAsync()
        {
            return (await _context.SaveChangesAsync() >= 0);
        }
    }
}
